//
// Created by baka on 2025/10/17.
//

#include "UserFat32.h"
#include "fatfs.h"
#include "uart_printf.h"

uint8_t u8chr[] = "hello FAT32";
uint32_t u32Wbytes;

void FAT32_INIT_TEST(void)
{
    MX_FATFS_Init();
    ERROR("FAT32 TEST");

    // if(f_open(&SDFile,(const char*)"fatfs.txt",FA_CREATE_ALWAYS|FA_WRITE) == FR_OK)
    // {
    //     if(f_write(&SDFile,u8chr,sizeof(u8chr),&u32Wbytes) == FR_OK)
    //     {
    //         VERBOSE("f_write(&SDFile,u8chr,sizeof(u8chr),&u32Wbytes) == FR_OK");
    //         f_close(&SDFile);
    //     }
    // }

    char read_buf[6000];
    UINT bytes_read = 0;
    if(f_open(&SDFile,(const char*)"/favicon.ico",FA_READ) == FR_OK)
    {
        FRESULT result = f_read(&SDFile, read_buf, 100, &bytes_read);
        while(bytes_read > 0)
        {
            INFO("ERROR %s\n", read_buf);
            result = f_read(&SDFile, read_buf, 100, &bytes_read);
        }
        // while (f_gets(read_buf,sizeof(read_buf),&SDFile))
        // {
        //     INFO("data->%s",read_buf);
        // }
        f_close(&SDFile);
    }
}


// void FAT32_SaveData(void)
// {
//     char buf[64] = "时间,温度,湿度,光照\r\n8:30,15,80,50";
//     if(f_mount(&SDFatFS,SDPath,1) == FR_OK)
//     {
//         if(f_open(&SDFile,(const char*)"data.csv",FA_CREATE_ALWAYS|FA_WRITE) == FR_OK)
//         {
//             if(f_write(&SDFile,buf,sizeof(buf),&u32Wbytes) == FR_OK)
//             {
//                 INFO("FAT32_SaveData save sucessful");
//                 VERBOSE("f_write(&SDFile,u8chr,sizeof(u8chr),&u32Wbytes) == FR_OK");
//                 f_close(&SDFile);
//             }
//         }
//     }
//
// }
